const config = require('../../config');

class Checkin {
    constructor(obj) {
        this.time = obj.formatTime;
        this.now_time = obj.time;
        this.duration = obj.body.minutes;
    }

    check() {
        let duration = this.duration;
        // 打卡时长 判空
        if (!duration) {
            return { success: false, msg: '参数错误' };
        }
        // 判断 打卡时长 格式是否正确
        try {
            duration = parseInt(duration);
        } catch (err) {
            return { success: false, msg: '打卡时长格式错误' };
        }
        // 打卡时长取值范围判断
        if (duration <= 0 || duration > config.checkin.maxCheckinDuration) {
            return { success: false, msg: '打卡时长 有误' };
        }
        return { success: true };
    }
}

module.exports = Checkin;